<?php
// +----------------------------------------------------------------------
// | INPHP
// | Copyright (c) 2023 https://inphp.cc All rights reserved.
// | Author: 幺月儿(https://gitee.com/lulanyin) Email: inphp@qq.com
// | 该文件的开源协议以所在项目的LICENSE文件为准，请遵守开源协议要求
// +----------------------------------------------------------------------
// | 标签文章列表
// +----------------------------------------------------------------------
namespace app\cms\http\web;

use app\cms\tags\archiveList;
use Inphp\Core\Context;
use Inphp\Core\Util\Str;

class tag extends controller
{
    public function index(?string $tag = null)
    {
        //设置当前展示页面类型
        Context::set("CMS_PAGE", "tag");
        $tag = $tag ?? GET("tag");
        $tag = !empty($tag) ? Str::trim($tag) : null;
        if (empty($tag)) {
            $this->show404();
            return;
        }
        //列表、分页
        $page = GET("page", 1);
        $page = is_numeric($page) && $page > 0 ? ceil($page) : 1;
        $total = GET("total", 30);
        $total = is_numeric($total) && $total > 0 ? ceil($total) : 30;
        $total = min($total, 100);
        $list = archiveList::process([
            "tags"          => $tag,
            "page"          => $page,
            "total"         => $total,
            "pager"         => true
        ]);
        viewAssign("list", $list);
        viewAssign("CMS_PAGE_TAG", $tag);
        viewAssign("CMS_PAGE_TITLE", $tag);


    }

    public function __call(string $name, array $arguments)
    {
        // TODO: Implement __call() method.
        $name = stripos($name, ".html") > 0 ? substr($name, 0, stripos($name, ".html")) : $name;
        if (!empty($name)) {
            $this->index($name);
            return;
        }
        $this->show404();
    }
}